/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.lua;

import java.awt.Color;
import net.worlds.Util;
import se.krka.kahlua.vm.JavaFunction;
import se.krka.kahlua.vm.LuaCallFrame;


public class ColorFunctions {
    public static class ColorTostring implements JavaFunction
    {

        public int call(LuaCallFrame callFrame, int nArguments) {
            callFrame.push(Util.colorToString((Color)callFrame.get(0)));
            return 1;
        }
    }
    public static class ColorIndex implements JavaFunction
    {
        public int call(LuaCallFrame callFrame, int nArguments) {
            Color color = (Color) callFrame.get(0);
            String k = callFrame.get(1).toString();
            if(k.equals("r"))
                callFrame.push(color.getRed());
            else if(k.equals("g"))
                callFrame.push(color.getGreen());
            else if(k.equals("b"))
                callFrame.push(color.getBlue());
            else
                throw new RuntimeException(k+" is not a member of Color");
            return 1;
        }
    }
    public static class ColorEq implements JavaFunction
    {
        public int call(LuaCallFrame callFrame, int nArguments) {
            final Color obj1 = (Color) callFrame.get(0);
            final Color obj2 = (Color) callFrame.get(1);
            callFrame.push(obj1.equals(obj2));
            return 1;
        }
    }
}
